import 'package:flutter/material.dart';

enum TextDeriction {
  TOP,
  BOTTOM,
  LEFT,
  RIGHT,
}

class IconWithText extends StatelessWidget {
  final IconData icon;
  final String text;
  final TextDeriction deriction;
  const IconWithText({Key key, this.icon, this.text, this.deriction})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Expanded(child: _buildText(deriction));
  }

  Widget _buildText(deriction) {
    if (deriction == TextDeriction.TOP) {
      return Column(
        mainAxisAlignment: MainAxisAlignment.center,
        mainAxisSize: MainAxisSize.max,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: <Widget>[
          Text(text,
              style: TextStyle(color: Colors.grey, fontSize: 14.0),
              overflow: TextOverflow.ellipsis,
              maxLines: 1),
          Padding(padding: EdgeInsets.only(top: 5.0)),
          Icon(icon, size: 16.0, color: Colors.grey),
        ],
      );
    }

    if (deriction == TextDeriction.RIGHT) {
      return Row(
        mainAxisAlignment: MainAxisAlignment.center,
        mainAxisSize: MainAxisSize.max,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: <Widget>[
          Icon(icon, size: 16.0, color: Colors.grey),
          Padding(padding: EdgeInsets.only(right: 5.0)),
          Text(text,
              style: TextStyle(color: Colors.grey, fontSize: 14.0),
              overflow: TextOverflow.ellipsis,
              maxLines: 1),
        ],
      );
    }

    if (deriction == TextDeriction.BOTTOM) {
      return Column(
        mainAxisAlignment: MainAxisAlignment.center,
        mainAxisSize: MainAxisSize.max,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: <Widget>[
          Icon(icon, size: 16.0, color: Colors.grey),
          Padding(padding: EdgeInsets.only(bottom: 5.0)),
          Text(text,
              style: TextStyle(color: Colors.grey, fontSize: 14.0),
              overflow: TextOverflow.ellipsis,
              maxLines: 1),
        ],
      );
    }

    if (deriction == TextDeriction.LEFT) {
      return Row(
        mainAxisAlignment: MainAxisAlignment.center,
        mainAxisSize: MainAxisSize.max,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: <Widget>[
          Text(text,
              style: TextStyle(color: Colors.grey, fontSize: 14.0),
              overflow: TextOverflow.ellipsis,
              maxLines: 1),
          Padding(padding: EdgeInsets.only(left: 5.0)),
          Icon(icon, size: 16.0, color: Colors.grey),
        ],
      );
    }

    return null;
  }
}
